package com.zsk.shop.controller.gop;

import com.zsk.shop.common.annotion.NoPermission;
import com.zsk.shop.common.base.BaseResponse;
import com.zsk.shop.common.utils.DateUtils;
import com.zsk.shop.common.utils.ToolUtil;
import com.zsk.shop.model.params.*;
import com.zsk.shop.model.results.*;
import com.zsk.shop.service.ShopOrderPointsService;
import com.zsk.shop.service.ShopUserService;
import com.zsk.shop.service.UserAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@RestController
@Api(tags = "GOP商城用户相关")
@RequestMapping("/gop/shopUser")
public class GopShopUserController {
    @Resource
    private UserAccountService userAccountService;
    @Resource
    private ShopUserService shopUserService;
    @Resource
    private ShopOrderPointsService shopOrderPointsService;

    @NoPermission
    @ApiOperation("小程序用户列表")
    @PostMapping("/gopShopUserList.do")
    public BaseResponse<List<GopShopUserListResult>> gopShopUserList(@RequestBody GopQueryUserListParams param) {
        return shopUserService.gopShopUserList(param);
    }

    @NoPermission
    @ApiOperation("小程序用户列表-设置分公司")
    @GetMapping("/gopShopUserSetSubCompany.do")
    public BaseResponse gopShopUserSetSubCompany(Long id, String subCompany, String pwd) {
        return shopUserService.gopShopUserSetSubCompany(id, subCompany, pwd);
    }

    @NoPermission
    @ApiOperation("小程序用户列表-删除分公司")
    @GetMapping("/gopShopUserDeletedSubCompany.do")
    public BaseResponse gopShopUserDeletedSubCompany(Long id, String pwd) {
        return shopUserService.gopShopUserDeletedSubCompany(id, pwd);
    }

    @ApiOperation("小程序用户详情")
    @GetMapping("/gopShopUserDetail.do")
    public BaseResponse<GopShopUserDetailResult> gopShopUserDetail(String userNo) {
        return shopUserService.gopShopUserDetail(userNo);
    }

    @NoPermission
    @ApiOperation("小程序用户详情-分公司管理统计1-分公司权限")
    @PostMapping("/gopShopUserSubCompanyInfoList.do")
    public BaseResponse<List<GopShopUserSubCompanyInfoListByMonthResult>> gopShopUserSubCompanyInfoList(@RequestBody GopShopUserSubCompanyInfoListParams params) {
        return shopUserService.gopShopUserSubCompanyInfoList(params);
    }

    @NoPermission
    @ApiOperation("小程序用户详情-分公司管理统计1-点击数量列表")
    @PostMapping("/gopShopUserSubCompanyInfoDetail.do")
    public BaseResponse<List<GopShopUserSubCompanyInfoUserDetailResult>> gopShopUserSubCompanyInfoDetail(@RequestBody GopShopUserSubCompanyInfoUserDetailParams params) {
        return shopUserService.gopShopUserSubCompanyInfoDetail(params);
    }

    @NoPermission
    @ApiOperation("小程序用户详情-管理统计")
    @PostMapping("/gopShopUserSubCompanyInfoListPeo.do")
    public BaseResponse<List<GopShopUserSubCompanyInfoListByMonthResult>> gopShopUserSubCompanyInfoListPeo(@RequestBody GopShopUserSubCompanyInfoListParams params) {
        return shopUserService.gopShopUserSubCompanyInfoListPeo(params);
    }

    @NoPermission
    @ApiOperation("小程序用户详情-管理统计-点击数量列表")
    @PostMapping("/gopShopUserSubCompanyInfoDetailPeo.do")
    public BaseResponse<List<GopShopUserSubCompanyInfoUserDetailResult>> gopShopUserSubCompanyInfoDetailPeo(@RequestBody GopShopUserSubCompanyInfoUserDetailParams params) {
        return shopUserService.gopShopUserSubCompanyInfoDetailPeo(params);
    }

    @ApiOperation("小程序用户详情-添加账户余额")
    @PostMapping("/addUserAccount.do")
    public BaseResponse addUserAccount(@RequestBody GopAddUserAccountParams params) {
        return userAccountService.addUserAccount(params);
    }

    @ApiOperation("小程序用户详情-邀请人数（一级）分页")
    @PostMapping("/gopShopUserInviteUser.do")
    public BaseResponse<List<GopShopUserInviteUserResult>> gopShopUserInviteUser(@RequestBody GopShopUserInviteUserParams params) {
        return shopUserService.gopShopUserInviteUser(params);
    }

    @NoPermission
    @ApiOperation("小程序用户详情-团队业绩(及礼包统计—>推广礼包统计)-按时间")
    @PostMapping("/shopUserTeamBuySpecialGoodsList.do")
    public BaseResponse<List<GopShopUserTeamBuySpecialGoodsResult>> shopUserTeamBuySpecialGoodsList(@RequestBody TeamBuySpecialGoodsParams params) {
        if (ToolUtil.isEmpty(params.getUserNo())) {
            return BaseResponse.error("当前用户不存在。");
        }
        return shopUserService.shopUserTeamBuySpecialGoodsList(params);
    }

    @NoPermission
    @ApiOperation("小程序用户详情-用户积分明细列表")
    @GetMapping("/shopUserPointDetailList.do")
    public BaseResponse<ShopUserPointDetailResult> shopUserPointDetailList(String userNo, String page, String limit) {
        if (ToolUtil.isEmpty(userNo)) {
            return BaseResponse.error("当前用户不存在。");
        }
        return shopOrderPointsService.shopUserPointDetail("", userNo, page, limit);
    }

    @NoPermission
    @ApiOperation("小程序用户详情-用户积分明细详情")
    @GetMapping("/ShopOrderPointsDetail.do")
    public BaseResponse<ShopOrderPointsDetailResult> shopOrderPointsDetailDetail(String orderPointsNo, String page, String limit) {
        return shopOrderPointsService.shopOrderPointsDetailDetail(orderPointsNo, page, limit);
    }

    @NoPermission
    @ApiOperation("小程序用户详情-用户账户余额流水")
    @PostMapping("/gopShopUserAccountList.do")
    public BaseResponse<ShopUserAccountListResult> gopShopUserAccountList(@RequestBody GopShopUserAccountListParams params) {
        if (ToolUtil.isEmpty(params.getUserNo())) {
            return BaseResponse.error("用户有误");
        }
        return userAccountService.gopShopUserAccountList(params);
    }

    @NoPermission
    @ApiOperation("小程序用户详情-直推统计（除2后）")
    @GetMapping("/gopShopUserSixUserList.do")
    public BaseResponse<ShopUserSixUserListResult> gopShopUserSixUserList(String userNo, String monthInfo) {
        if (ToolUtil.isEmpty(userNo)) {
            return BaseResponse.error("用户有误");
        }
        if (ToolUtil.isEmpty(monthInfo)) {
            monthInfo = DateUtils.format(new Date(), DateUtils.YYYYMM);
        }
        String startTime = DateUtils.getMonthStartTimeStr(DateUtils.parse2Date(monthInfo, DateUtils.YYYYMM));
        String endTime = DateUtils.getMonthEndTimeStr(DateUtils.parse2Date(monthInfo, DateUtils.YYYYMM));
        return shopUserService.gopShopUserSixUserList(userNo, startTime, endTime);
    }
}
